package com.digital.smartgrow.service.business.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.digital.smartgrow.dto.business.UpPubilcityPageDTO;
import com.digital.smartgrow.entity.business.UpJob;
import com.digital.smartgrow.entity.business.UpJobLog;
import com.digital.smartgrow.entity.business.UpPubilcity;
import com.digital.smartgrow.dao.business.UpPubilcityMapper;
import com.digital.smartgrow.entity.sysinfo.DictionaryItem;
import com.digital.smartgrow.service.business.UpJobService;
import com.digital.smartgrow.service.business.UpPubilcityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 晋升公示 服务实现类
 * </p>
 *
 * @author sunyuechao
 * @since 2022-08-31
 */
@Service
public class UpPubilcityServiceImpl extends ServiceImpl<UpPubilcityMapper, UpPubilcity> implements UpPubilcityService {
   @Autowired
   private UpJobService upJobService;
    @Override
    public Object getListByPage(UpPubilcityPageDTO pageDTO) {
        Page<UpPubilcity> page = new Page<>(pageDTO.getPageNum(), pageDTO.getPageSize());
        QueryWrapper<UpPubilcity> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(pageDTO.getTitle()), "title", pageDTO.getTitle());
        //一对一查询
        if(StringUtils.isNotBlank(pageDTO.getSeries())||StringUtils.isNotBlank(pageDTO.getYear())){
            List<UpJob> upJobs = upJobService.lambdaQuery().eq(UpJob::getSeries, pageDTO.getSeries()).eq(UpJob::getYear, pageDTO.getYear()).list();
            if(upJobs.size()>0){
                for (UpJob j:upJobs) {
                    queryWrapper
                            .or(
                                    wrapper -> wrapper.eq("upJobId", j.getId())
                            );
                }
            }
        }
//        for (UpJob j:upJobs) {
//            queryWrapper.eq("upJobId",j.getId());
//        }
        return this.page(page, queryWrapper);
    }

    @Override
    public Object getInfo(Integer id) {
        return this.getById(id);
    }
}
